﻿@using System.Data;
@using System.Web;
@using DTcms.Web.MVC.Areas.Web.Controllers;
@using DTcms.Web.MVC.UI.Controllers;
@using DTcms.Model;
@{
   Layout = "~/Areas/Web/Views/" + ViewBag.TemplateSkin + "/Shared/_LayoutShow.cshtml";
   DTcms.Model.sites site = ViewData["site"] as DTcms.Model.sites;
   DTcms.Model.sysconfig config = ViewData["sysConfig"] as DTcms.Model.sysconfig;
   BaseController bc = ViewBag.BasePage as BaseController;
   ViewBag.Title = "确认订单 - " + site.name;
   DTcms.Model.users userModel = ViewData["userModel"] as DTcms.Model.users;
   List<DTcms.Model.cart_items> goodsList = ViewData["goodsList"] as List<DTcms.Model.cart_items>;
   DTcms.Model.cart_total goodsTotal = ViewData["goodsTotal"] as DTcms.Model.cart_total;
   DTcms.Model.orderconfig orderConfig = ViewData["orderConfig"] as DTcms.Model.orderconfig;

   DataTable paymentList = bc.get_payment_list(0, "is_lock=0"); //支付方式
   DataTable expressList = bc.get_express_list(0, "is_lock=0"); //配送方式
}
@section HeaderContent{
   <script src="~/Scripts/jquery/jquery.form.min.js"></script>
   <script src="~/Scripts/PCASClass.js"></script>
   <script src="~/Areas/Web/Scripts/cart.js"></script>
}
@section Scripts{
<script>
   $(function () {
      //初始化收货地址
      initUserAddress("#userAddress");
      //初始化表单
      AjaxInitForm('#orderForm', '#btnSubmit', 0);
   });
</script>
}
<div class="section clearfix">
  <div class="cart-box">
    <h1>确认订单信息</h1>
    <div class="cart-step">
      <ul>
        <li class="item"><span>1</span>放进购物车</li>
        <li class="selected"><span>2</span>填写订单信息</li>
        <li class="last"><span>3</span>支付/确定订单</li>
      </ul>
    </div>
  </div>
  
  <div class="line30"></div>
  <h3 class="bar-tit">1、收货地址</h3>

@if (userModel != null) {
   DataTable addrList = bc.get_user_addr_book_list(0, "user_id=" + userModel.id);
  <ul id="userAddress" class="address-list">
    @foreach (DataRow dr in addrList.Rows) {
      <li class="@(dr["is_default"].ToString() == "1" ? "selected" : "")">
        <label>
          <input name="user_book_id" type="radio" value="@dr["id"]" />
          <span>@dr["area"]@dr["address"] (@dr["accept_name"] 收)</span>
          <em>@dr["mobile"]</em>
        </label>
        <input name="user_accept_name" type="hidden" value="@dr["accept_name"]" />
        <input name="user_area" type="hidden" value="@dr["area"]" />
        <input name="user_address" type="hidden" value="@dr["address"]" />
        <input name="user_mobile" type="hidden" value="@dr["mobile"]" />
        <input name="user_telphone" type="hidden" value="@dr["telphone"]" />
        <input name="user_email" type="hidden" value="@dr["email"]" />
      <input name="user_post_code" type="hidden" value="@dr["post_code"]" />
      </li>
    }
  </ul>
}
  
  <form id="orderForm" name="orderForm" url="@(config.webpath)tools/submit_ajax.ashx?action=order_save&site_id=@site.id">
  <div class="form-box address-info">
    <dl>
      <dt>收货人姓名：</dt>
      <dd>
        <input name="book_id" id="book_id" type="hidden" value="0" />
        <input name="accept_name" id="accept_name" type="text" class="input txt wide" value="" datatype="s2-20" sucmsg=" " />
        <span class="Validform_checktip">*收货人姓名</span>
      </dd>
    </dl>
    <dl>
      <dt>所属地区：</dt>
      <dd>
        <select id="province" name="province" class="select"></select>
        <select id="city" name="city" class="select"></select>
        <select id="area" name="area" class="select" datatype="*" sucmsg=" "></select>
        <span class="Validform_checktip">*请选择您所在的地区</span>
      </dd>
    </dl>
    <dl>
      <dt>详细地址：</dt>
      <dd>
        <input name="address" id="address" type="text" class="input txt" value="" datatype="*2-100" sucmsg=" " style="width:300px;" />
        <span class="Validform_checktip">*除上面所属地区外的详细地址</span>
      </dd>
    </dl>
    <dl>
      <dt>手机号码：</dt>
      <dd>
        <input name="mobile" id="mobile" type="text" class="input txt" value="" datatype="m" sucmsg=" " />
        <span class="Validform_checktip">*收货人的手机号码</span>
      </dd>
    </dl>
    <dl>
      <dt>联系电话：</dt>
      <dd>
        <input name="telphone" id="telphone" type="text" class="input txt" value="" />
        <span class="Validform_checktip">收货人的联系电话，非必填</span>
      </dd>
    </dl>
    <dl>
      <dt>电子邮箱：</dt>
      <dd>
        <input name="email" id="email" type="text" class="input txt" value="" />
        <span class="Validform_checktip">方便通知订单状态，非必填</span>
      </dd>
    </dl>
    <dl>
      <dt>邮政编码：</dt>
      <dd>
        <input name="post_code" id="post_code" type="txt" class="input txt" />
        <span class="Validform_checktip">所在地区的邮政编码，非必填</span>
      </dd>
    </dl>
  </div>
  
  <div class="line30"></div>
  <h3 class="bar-tit">2、支付方式</h3>
  <ul class="item-box">
     @for (int i = 0; i < paymentList.Rows.Count; i++) {
        DataRow dr1 = paymentList.Rows[i];
        decimal poundage_amount = bc.get_payment_poundage_amount(Convert.ToInt32(dr1["id"]), goodsTotal.real_amount);
       <li>
         <label>
         @if (i == paymentList.Rows.Count - 1) {
           <input name="payment_id" type="radio" onclick="paymentAmountTotal(this);" value="@dr1["id"]" datatype="*" sucmsg=" " />
           <input name="payment_price" type="hidden" value="@poundage_amount" />@dr1["title"]
         }
         else {
           <input name="payment_id" type="radio" onclick="paymentAmountTotal(this);" value="@dr1["id"]" />
           <input name="payment_price" type="hidden" value="@poundage_amount" />@dr1["title"]
         }
           <em>手续费：@poundage_amount 元</em>
         </label>
       </li>
     }
  </ul>
  
  <div class="line30"></div>
  <h3 class="bar-tit">3、配送方式</h3>
  <ul class="item-box">
       @for (int i = 0; i < expressList.Rows.Count; i++) {
          DataRow dr2 = expressList.Rows[i];
         <li>
           <label>
           @if (i == expressList.Rows.Count - 1) {
             <input name="express_id" type="radio" onclick="freightAmountTotal(this);" value="@dr2["id"]" datatype="*" sucmsg=" " />
             <input name="express_price" type="hidden" value="@dr2["express_fee"]" />@dr2["title"]
           }
           else {
             <input name="express_id" type="radio" onclick="freightAmountTotal(this);" value="@dr2["id"]" />
             <input name="express_price" type="hidden" value="@dr2["express_fee"]" />@dr2["title"]
           }
             <em>费用：@dr2["express_fee"] 元</em>
           </label>
         </li>
       }
  </ul>
    
  <div class="line30"></div>
  <h3 class="bar-tit">4、商品清单</h3>
  <table width="100%" border="0" align="center" cellpadding="8" cellspacing="0" class="cart-table">
    <tr>
      <th colspan="2" align="left">商品信息</th>
      <th width="84" align="left">单价</th>
      <th width="84" align="left">优惠(元)</th>
      <th width="84" align="center">数量</th>
      <th width="104" align="left">金额(元)</th>
      <th width="84" align="left">积分</th>
      <th width="84" align="center">库存(件)</th>
    </tr>
    @foreach (DTcms.Model.cart_items modelt in goodsList) {
    <tr>
      <td width="68">
        <a target="_blank" href="@bc.linkurl("goods_show", modelt.article_id)">
          <img src="@modelt.img_url" class="img" />
        </a>
      </td>
      <td>
        <a target="_blank" href="@bc.linkurl("goods_show", modelt.article_id)">@modelt.title</a>
        <p class="stxt">@modelt.spec_text</p>
      </td>
      <td>
        <span class="red">
          ￥@modelt.user_price
        </span>
      </td>
      <td>
        <span class="red">
          ￥@(modelt.sell_price - modelt.user_price)
        </span>
      </td>
      <td align="center">@modelt.quantity</td>
      <td>
        <span class="red">
          ￥@(modelt.user_price * modelt.quantity)
        </span>
      </td>
      <td align="center">
        @(modelt.point > 0 ? "+" : "")@(modelt.point * modelt.quantity)
      </td>
      <td align="center">
        @modelt.stock_quantity
      </td>
    </tr>
    }
    @if (goodsList.Count == 0) {
    <tr>
      <td colspan="8">
        <div class="msg-tips">
          <div class="ico warning"></div>
          <div class="msg">
            <strong>购物车没有商品！</strong>
            <p>您的购物车为空，<a href="@bc.linkurl("index")">马上去购物</a>吧！</p>
          </div>
        </div>
      </td>
   </tr>
    }
  </table>
  
  <div class="line30"></div>
  <h3 class="bar-tit">5、结算信息</h3>
  <div class="buy-foot">
    <div class="left">
      <dl>
        <dd>
          <label><input name="is_invoice" id="is_invoice" type="checkbox" value="1" onclick="taxAmoutTotal(this);" /> 是否开具发票</label>
          <input name="taxAmout" id="taxAmout" type="hidden" value="@bc.get_order_taxamount(goodsTotal.real_amount)" />
        </dd>
      </dl>
      <dl id="invoiceBox" style="display:none;">
        <dt>发票抬头(100字符以内)</dt>
        <dd>
           <input name="invoice_title" id="invoice_title" type="text" class="input" />
        </dd>
      </dl>
      <dl>
        <dt>订单备注(100字符以内)</dt>
        <dd>
          <textarea name="message" class="input" style="height:35px;"></textarea>
        </dd>
      </dl>
    </div>
    <div class="right">
      <p>
        商品 <label class="price">@goodsTotal.total_quantity</label> 件&nbsp;&nbsp;&nbsp;&nbsp;
        商品金额：￥<label id="goodsAmount" class="price">@goodsTotal.real_amount</label> 元&nbsp;&nbsp;&nbsp;&nbsp;
        总积分：<label class="price">@goodsTotal.total_point</label> 分
      </p>
      <p>
        运费：￥<label id="expressFee" class="price">0.00</label> 元 +
        支付手续费：￥<label id="paymentFee" class="price">0.00</label> 元 +
        税费：￥<label id="taxesFee" class="price">0.00</label> 元
      </p>
      <p class="txt-box">
        应付总金额：￥<label id="totalAmount" class="price">@goodsTotal.real_amount</label>
      </p>
      <p class="btn-box">
        <a class="btn" href="@bc.linkurl("cart")">返回购物车</a>
        @if (goodsTotal.total_quantity > 0) {
        <input id="btnSubmit" name="btnSubmit" type="submit" value="确认提交" class="btn btn-success" />
        }
        else {
        <input id="btnSubmit" name="btnSubmit" type="button" value="确认提交" class="btn btn-gray" disabled="disabled" />
        }
      </p>
    </div>
  </div>
  <div class="clear"></div>
  </form>
</div>